﻿using Architecture.API.Application.Command.MenuCommand;
using Architecture.API.Application.Command.MenuRoleCommand;
using Architecture.Domain;
using Architecture.Domain.Service.MenuRoleServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.MenuRoleCommandHandler
{
    /// <summary>
    /// 菜单角色创建命令处理器
    /// </summary>
    public class MenuRoleCreateCommandHandler : IRequestHandler<MenuRoleCreateCommand, int>
    {
        /// <summary>
        /// 菜单角色服务
        /// </summary>
        protected readonly IMenuRoleService _menuRoleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="menuRoleService">菜单角色服务</param>
        public MenuRoleCreateCommandHandler(IMenuRoleService menuRoleService)
        {
            _menuRoleService = menuRoleService;
        }

        /// <summary>
        /// 处理菜单角色创建命令
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(MenuRoleCreateCommand request, CancellationToken cancellationToken)
        {
            return await _menuRoleService.AddMenuRole(new AddMenuRole() { rid = request.rid, ids = request.ids });
        }
    }
}
